package com.dp.mallchat.common.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dp.mallchat.common.user.dao.RoleDao;
import com.dp.mallchat.common.user.dao.UserRoleDao;
import com.dp.mallchat.common.user.domain.user.entity.Role;
import com.dp.mallchat.common.user.domain.user.enums.RoleEnum;
import com.dp.mallchat.common.user.mapper.RoleMapper;
import com.dp.mallchat.common.user.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Set;

/**
 * @Author: dupeng
 * @CreateTime: 2024-06-13  16:03
 * @Description: 角色实现类
 */
@Service
@Slf4j
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Autowired
    private RoleDao roleDao;
    @Autowired
    private UserRoleDao userRoleDao;

    @Override
    public boolean hasPower(Long uid, RoleEnum admin) {
        //获取用户所有角色
        Set<Long> listRoleId = userRoleDao.listRoleId(uid);

        //判断用户是否有这个角色
        return !CollectionUtils.isEmpty(listRoleId) && listRoleId.contains(admin.getType());
    }


}
